<!DOCTYPE html>
<html lang="en">
<head>
    <include file="Public:header2" />
    <title>{:C('web_title')}</title>
</head>
<body class="blackbg">
    <div id="container" class="logbg">
        <div class="log_title">
            <span class="back"><a href="javascript:history.go(-1)"></a></span>
            {$Think.lang.g_modify_loginpwd}
        </div>
        <div class="logbot">
            <form id="form-cnyin">
				<input type="password" class="logipt" id="oldpassword" placeholder="{$Think.lang.g_denglumm}" onkeyup="chkpwd();" maxlength="16" onblur="chkoldpassword();"/>

				<input type="password" id="newpassword" class="logipt" placeholder="{$Think.lang.User_xdlmmgs}" onkeyup="chknewpwd();" maxlength="16" onblur="chknewpassword();"/>

				<input type="password" id="repassword" class="logipt" placeholder="{$Think.lang.User_qrxmmgs}" onkeyup="rechknewpwd();" maxlength="16" onblur="chkrepassword();"/>

<!--				<select id="chkstyle" class="logipt">
					<option value="">请选择验证方式</option>
					<option value="mobile">手机号码验证</option>
					<option value="email">邮箱验证</option>
				</select>-->

				<!--<div class="yzmbox" id="mobile_div" style="display:none;">
					<input type="text" id="mobile_verify" value="" class="logipt yzmipt" placeholder="短信验证码" />
					<input type="button" id="regBtn" onclick="SendCode()" value="点击获取验证码" class="phonebut" />
					<if condition="$user['email'] eq '' || $user['email'] eq null">
						<p class="attention">您没有绑定手机，请先绑定手机或换成其它验证方式</p>
					<else />
						<p class="attention">* 接收短信的手机{$user['mobile']|addstar=###,mobile}</p>
					</if>
				</div>-->

				<div class="yzmbox" id="email_div">
					<input type="text" id="email_verify" value="" class="logipt yzmipt" maxlength="6" placeholder="{$Think.lang.g_yx_verify}" />
					<input type="button" id="regBtn" onclick="EmCode()" value="{$Think.lang.Finance_hqyzm2}" class="phonebut" />
					<if condition="$user['email'] eq '' || $user['email'] eq null">
						<p class="attention">您没有绑定邮箱，请先绑定邮箱或换成其它验证方式</p>
					<else />
						<p class="attention">* {$Think.lang.g_pwd_yx_recode}{$user['email']|addstar=###,email}</p>
					</if>
				</div>

				<p class="attention">
					{$Think.lang.g_pwd_notice}
				</p>

				<input type="button" class="logbut" id="btn-submit" value="{$Think.lang.User_save}" title="{$Think.lang.User_save}" onclick="Update()"/>
			</form>
        </div>
    </div>
<script type="text/javascript">
	$("#chkstyle").change(function(){
	    if($(this).val()=="mobile"){
	      $("#mobile_div").show();
	      $("#email_div").hide();
	    }else if($(this).val()=="email"){
	      $("#mobile_div").hide();
	      $("#email_div").show();
	    }
	  });

	function SendCode() {
		layer.load(0, {shade: [0.5,'#8F8F8F']});
	    $('#regBtn').attr("disabled", "disabled");
	    $.post("{:U('Verify/pass')}", {}, function (data) {
		  layer.closeAll();
	      if (data.status == 1) {
	        layer.msg(data.info, {
	          icon: 1
	        });
	        var obj = $('#regBtn');
	        var wait = 60;
	        var interval = setInterval(function () {
	          obj.css('backgroundColor', '#135f91');
	          obj.val(wait + '秒再次发送');
	          wait--;
	          if (wait < 0) {
	            obj.removeAttr("disabled");
	            clearInterval(interval);
	            obj.val('获取验证码');
	            obj.css('backgroundColor', '#135f91');
	          }
	          ;
	        }, 1000);
	      } else {
	        $('#regBtn').removeAttr("disabled");
	        layer.msg(data.info, {
	          icon: 2
	        });
	      }
	    }, "json");
	}

	function EmCode() {
	  var chkstyle = 'email';
	  if(!chkstyle || chkstyle != 'email'){
	  layer.tips('您选择的验证方式不是邮箱验证', '#chkstyle', {
	        tips: 3
	    });
	    return false;
	  }
	  layer.load(0, {shade: [0.5,'#8F8F8F']});
	    $('#regBtn').attr("disabled", "disabled");
	    $.post("{:U('Verify/passemail')}", {}, function (data) {
	    layer.closeAll();
	      if (data.status == 1) {
	        layer.msg(data.info, {
	          icon: 1
	        });
	        var obj = $('#regBtn');
	        var wait = 120;
	        var interval = setInterval(function () {
	          obj.css('backgroundColor', '#135f91');
	          obj.val(wait + '{$Think.lang.sFinance_myzc_mzcfs}');
	          wait--;
	          if (wait < 0) {
	            obj.removeAttr("disabled");
	            clearInterval(interval);
	            obj.val('{$Think.lang.sFinance_myzc_hqyzm}');
	            obj.css('backgroundColor', '#135f91');
	          }
	          ;
	        }, 1000);
	      } else {
	        $('#regBtn').removeAttr("disabled");
	        layer.msg(data.info, {
	          icon: 2
	        });
	      }
	    }, "json");
	}

	function Update() {

		var oldpassword = $("#oldpassword").val();
	    var newpassword = $("#newpassword").val();
	    var repassword = $("#repassword").val();
	    var mobile_verify = $("#mobile_verify").val();
	    var chkstyle = 'email';
    	var email_verify = $("#email_verify").val();
    	if(!chkstyle){
	      layer.tips('您选择验证方式！', '#chkstyle', {
	        tips: 3
	      });
	      return false;
	    }

/*	    if (chkstyle == 'mobile' && (mobile_verify == "" || mobile_verify == null)) {
	      layer.tips('请输入短信验证码', '#mobile_verify', {
	        tips: 3
	      });
	      return false;
	    }*/

	    if (chkstyle == 'email' && (email_verify == "" || email_verify == null)) {
	      layer.tips('{$Think.lang.sFinance_myzc_qsryxyzm}', '#email_verify', {
	        tips: 3
	      });
	      return false;
	    }

	    if (newpassword == "" || newpassword == null) {
	      layer.tips('{$Think.lang.User_rsnewdlmm}', '#newpassword', {
	        tips: 3
	      });
	      return false;
	    }

	    if (oldpassword == "" || oldpassword == null) {
	      layer.tips('{$Think.lang.User_rsolddlmm}', '#oldpassword', {
	        tips: 3
	      });
	      return false;
	    }

	     if (repassword == "" || repassword == null) {
	      layer.tips('{$Think.lang.User_rsenterdlmm}', '#repassword', {
	        tips: 3
	      });
	      return false;
	    }

		$.post("{:U('User/uppassword')}", {
			oldpassword: $('#oldpassword').val(),
			newpassword: $('#newpassword').val(),
			//mobile_verify: $('#mobile_verify').val(),
			repassword: $('#repassword').val(),
			chkstyle: chkstyle,
			email_verify: email_verify
		}, function (data) {
			if (data.status == 1) {
				layer.msg(data.info, {icon: 1});
				window.location = "{:U('Login/loginout')}";
			} else {
				layer.msg(data.info, {icon: 2});
				if (data.url) {
					window.location = data.url;
				}
			}
		}, "json");
	}

	function chkpwd(){
		var password = $("#oldpassword").val();
		var patten =/^[a-zA-Z0-9]+$/;
		var match = new RegExp(patten);
		if (!match.test(password)) {
			layer.tips('{$Think.lang.User_mmgs2}','#oldpassword',{tips:3});
			var result = password.substring(0,password.length-1);
			$("#oldpassword").val(result);
		}
	}
	function chknewpwd(){
		var newpassword = $("#newpassword").val();
		var patten =/^[a-zA-Z0-9]+$/;
		var match = new RegExp(patten);
		if (!match.test(newpassword)) {
			layer.tips('{$Think.lang.User_mmgs2}','#newpassword',{tips:3});
			var result = newpassword.substring(0,newpassword.length-1);
			$("#newpassword").val(result);
		}
	}
	function rechknewpwd(){
		var repassword = $("#repassword").val();
		var patten =/^[a-zA-Z0-9]+$/;
		var match = new RegExp(patten);
		if (!match.test(repassword)) {
			layer.tips('{$Think.lang.User_mmgs2}','#repassword',{tips:3});
			var result = repassword.substring(0,repassword.length-1);
			$("#repassword").val(result);
		}
	}
	function chkoldpassword(){
		var oldpassword = $("#oldpassword").val();
		if(!oldpassword){
			layer.tips("{$Think.lang.User_rsolddlmm}",'#oldpassword',{tips:3});
		}
	}
	function chknewpassword(){
		var newpassword = $("#newpassword").val();
		if(!newpassword){
			layer.tips("{$Think.lang.User_rsnewdlmm}",'#newpassword',{tips:3});
		}
	}
	function chkrepassword(){
		var repassword = $("#repassword").val();
		if(!repassword){
			layer.tips("{$Think.lang.User_rsolddlmm2}",'#repassword',{tips:3});
		}
	}
	function chkmobileverify(){
		var mobileverify = $("#mobile_verify").val();
		if(!mobileverify){
			layer.tips("请输入手机验证码！",'#mobile_verify',{tips:3});
		}
	}
</script>
<include file="Public:footer" />
</body>
</html>